# Copyright (C) 2020 The Dagger Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Description:
#   Tests for internal code for implementing Hilt processors.

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

package(default_visibility = ["//:src"])

# Checks that multiple test roots can be compiled together. This library
# only compiles the sources. they are tested in the android_local_tests.
android_library(
    name = "multi_test_root_tests",
    srcs = [
        "ActivityScenarioRuleTest.java",
        "CustomTestApplicationTest.java",
        "MultiTestRoot1Test.java",
        "MultiTestRoot2Test.java",
        "MultiTestRootExternalModules.java",
    ],
    exports_manifest = 1,
    manifest = "AndroidManifest.xml",
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:entry_point",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/testing:bind_value",
        "//java/dagger/hilt/android/testing:custom_test_application",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "//java/dagger/hilt/android/testing:uninstall_modules",
        "@google_bazel_common//third_party/java/truth",
        "@maven//:androidx_test_ext_junit",
        "@maven//:junit_junit",
        "@maven//:org_robolectric_robolectric",
    ],
)

android_local_test(
    name = "ActivityScenarioRuleTest",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        ":multi_test_root_tests",
    ],
)

android_local_test(
    name = "CustomTestApplicationTest",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        ":multi_test_root_tests",
    ],
)

android_local_test(
    name = "MultiTestRoot1Test",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        ":multi_test_root_tests",
    ],
)

android_local_test(
    name = "MultiTestRoot2Test",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        ":multi_test_root_tests",
    ],
)

android_local_test(
    name = "AndroidEntryPointBaseClassTest",
    size = "small",
    srcs = [
        "AndroidEntryPointBaseClassOtherPkg.java",
        "AndroidEntryPointBaseClassTest.java",
    ],
    javacopts = [
        # Note: Hilt's bytecode injection doesn't work in Blaze but we disable
        # superclass validation in this test just to verify everything builds.
        "-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true",
        # Note: Used to test base classes across java packages.
        "-Xep:PackageLocation:OFF",
    ],
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "@google_bazel_common//third_party/java/truth",
    ],
)

android_local_test(
    name = "ModuleTest",
    srcs = ["ModuleTest.java"],
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "@google_bazel_common//third_party/java/jsr330_inject",
        "@google_bazel_common//third_party/java/truth",
    ],
)

android_local_test(
    name = "InjectionTest",
    size = "small",
    srcs = ["InjectionTest.java"],
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "@google_bazel_common//third_party/java/jsr330_inject",
        "@google_bazel_common//third_party/java/truth",
    ],
)

android_local_test(
    name = "InstallInObjectModuleTest",
    srcs = ["InstallInObjectModuleTest.java"],
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        ":InstallInObjectModuleClasses",
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:entry_point",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "@google_bazel_common//third_party/java/junit",
        "@google_bazel_common//third_party/java/truth",
    ],
)

kt_android_library(
    name = "InstallInObjectModuleClasses",
    testonly = True,
    srcs = ["InstallInObjectModule.kt"],
    deps = [
        "//:dagger_with_compiler",
        "//java/dagger/hilt:entry_point",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/components",
    ],
)

android_local_test(
    name = "DefaultViewModelFactoryTest",
    srcs = ["DefaultViewModelFactoryTest.java"],
    manifest = "AndroidManifest.xml",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:entry_point",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/lifecycle",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "@google_bazel_common//third_party/java/jsr330_inject",
        "@google_bazel_common//third_party/java/truth",
        "@maven//:androidx_activity_activity",
        "@maven//:androidx_fragment_fragment",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel_savedstate",
        "@maven//:junit_junit",
    ],
)

android_local_test(
    name = "QualifierInKotlinFieldsTest",
    srcs = ["QualifierInKotlinFieldsTest.java"],
    manifest = "AndroidManifest.xml",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        ":QualifierInFieldsClass",
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "@google_bazel_common//third_party/java/jsr330_inject",
        "@google_bazel_common//third_party/java/truth",
        "@maven//:androidx_activity_activity",
        "@maven//:androidx_fragment_fragment",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel_savedstate",
        "@maven//:junit_junit",
    ],
)

kt_android_library(
    name = "QualifierInFieldsClass",
    testonly = True,
    srcs = ["QualifierInFieldsClass.kt"],
    deps = [
        "//:dagger_with_compiler",
        "//java/dagger/hilt/android/qualifiers",
    ],
)

android_local_test(
    name = "ActivityRetainedClearedListenerTest",
    srcs = ["ActivityRetainedClearedListenerTest.java"],
    manifest = "AndroidManifest.xml",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:entry_point",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:activity_retained_lifecycle",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "@google_bazel_common//third_party/java/jsr330_inject",
        "@google_bazel_common//third_party/java/truth",
        "@maven//:androidx_activity_activity",
        "@maven//:androidx_fragment_fragment",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel_savedstate",
        "@maven//:junit_junit",
    ],
)

android_local_test(
    name = "ActivityInjectedViewModelTest",
    srcs = ["ActivityInjectedViewModelTest.java"],
    manifest = "AndroidManifest.xml",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:entry_point",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "@google_bazel_common//third_party/java/jsr330_inject",
        "@google_bazel_common//third_party/java/truth",
        "@maven//:androidx_activity_activity",
        "@maven//:androidx_fragment_fragment",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel_savedstate",
        "@maven//:junit_junit",
    ],
)

android_local_test(
    name = "ViewModelScopedTest",
    srcs = ["ViewModelScopedTest.java"],
    manifest = "AndroidManifest.xml",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:entry_point",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/lifecycle",
        "//java/dagger/hilt/android/scopes:view_model_scoped",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "@google_bazel_common//third_party/java/jsr330_inject",
        "@google_bazel_common//third_party/java/truth",
        "@maven//:androidx_activity_activity",
        "@maven//:androidx_fragment_fragment",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel_savedstate",
        "@maven//:junit_junit",
    ],
)

android_local_test(
    name = "ViewModelWithBaseTest",
    srcs = ["ViewModelWithBaseTest.java"],
    manifest = "AndroidManifest.xml",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:entry_point",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/lifecycle",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "@google_bazel_common//third_party/java/jsr330_inject",
        "@google_bazel_common//third_party/java/truth",
        "@maven//:androidx_activity_activity",
        "@maven//:androidx_fragment_fragment",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel",
        "@maven//:androidx_lifecycle_lifecycle_viewmodel_savedstate",
        "@maven//:junit_junit",
    ],
)

android_local_test(
    name = "ActivityInjectedSavedStateViewModelTest",
    srcs = ["ActivityInjectedSavedStateViewModelTest.java"],
    manifest = "AndroidManifest.xml",
    manifest_values = {
        "minSdkVersion": "14",
    },
    deps = [
        "//:android_local_test_exports",
        "//:dagger_with_compiler",
        "//java/dagger/hilt:entry_point",
        "//java/dagger/hilt:install_in",
        "//java/dagger/hilt/android:android_entry_point",
        "//java/dagger/hilt/android:package_info",
        "//java/dagger/hilt/android/testing:hilt_android_test",
        "//java/dagger/internal/guava:base-android",
        "@google_bazel_common//third_party/java/jsr330_inject",
        "@google_bazel_common//third_party/java/truth",
        "@maven//:junit_junit",
    ],
)
